package cn.csust.net2.manager.server.service.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import cn.csust.net2.manager.server.dao.ParameterDAO;
import cn.csust.net2.manager.shared.exception.BeyondAuthorityException;
import cn.csust.net2.manager.shared.po.Parameter;
import cn.csust.net2.manager.shared.service.SetParameterService;
import cn.csust.net2.manager.shared.util.Constant;
import cn.csust.net2.manager.shared.util.ServiceConstant;

@Service(value = ServiceConstant.SERVICE_NAME_SETPARAMETER)
public class SetParameterServiceImpl extends BaseServiceImpl  implements SetParameterService {
	@Resource(name = Constant.DAO_NAME_PARAMETER)
	private ParameterDAO parameterDAO;

	public ParameterDAO getParameterDAO() {
		return parameterDAO;
	}

	public void setParameterDAO(ParameterDAO parameterDAO) {
		this.parameterDAO = parameterDAO;
	}

	@Transactional
	@Override
	public Parameter find(String name)throws BeyondAuthorityException {
		// TODO Auto-generated method stub
		String hql = "from Parameter where paraName = '" + name + "'";
		return parameterDAO.findUniqueHQL(hql);
	}

	@Transactional
	@Override
	public void modify(String paraName, String value)throws BeyondAuthorityException {
		// TODO Auto-generated method stub
		String hql = "from Parameter where paraName = '" + paraName + "'";
		Parameter parameter = parameterDAO.findUniqueHQL(hql);
		parameter.setValue(value);
		this.parameterDAO.update(parameter);
	}
	
}
